package logic

import (
	"context"
	"gorm.io/gorm"
	"person/model/mysql"

	"person/personrpc/internal/svc"
	"person/personrpc/personrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserUpdateLogic {
	return &UserUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserUpdateLogic) UserUpdate(in *personrpc.UserUpdateRequest) (*personrpc.UserUpdateResponse, error) {
	// todo: add your logic here and delete this line
	finduser := mysql.Person{
		Model:  gorm.Model{ID: uint(in.Id)},
		UserId: int(in.Userid),
		Name:   in.Name,
		Price:  int(in.Price),
		Class:  in.Class,
	}
	mysql.DB.Debug().Updates(&finduser)
	return &personrpc.UserUpdateResponse{Id: int64(finduser.ID)}, nil
}
